import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * This class is an enemy subclass that will add objects of the class fire as time passes by and after
 * his X position is lower that 900.
 * 
 * @author Manuel Nava 
 * @version 0.9
 */
public class Boss extends Enemy
{
    private int resist;
    private boolean vulnerable;
    private int contAttack;
    
    /**
     * Constructor of the class boss, it sets the stamina level and the boolean vulnerable that 
     * indicates he can be removed after touching a weapon class object. Also it sets the counter
     * to attack after certain time.
     */
    public Boss()
    {
        resist=10;
        vulnerable=false;
        contAttack=0;
    }
    
    /**
     *The method act calls the superclass method move, also increments the attack counter, verify 
     *if it has taken damage or if thi object must been removed of the game.
     */
    public void act() 
    {
        setImage(new GreenfootImage("boss-stand.png"));
        contAttack++;
        super.move();
        if(contAttack>=100&&getX()<900)
        {
           attack();
           contAttack=0;
        }
        damage();
        if(resist<=0)
           vulnerable=true;
        deathly();
    }    
    
    /**
     * Adds a new Fire class object to the world.
     */
    public void attack()
    {
        setImage(new GreenfootImage("boss-attack1.png"));
        getWorld().addObject(new Fire(),getX()-45,getY());
    }
    
    /**
     * Remove the object of the world if is vulnerable.
     */
    public void deathly()
    {
        if(vulnerable==true)
        {
            getWorld().removeObject(this);
        }
    }
    
    /**
     * Sets the damage this object has taken and removes the object that causes that damage.
     */
    public void damage()
    {
        if(isTouching(Axe.class)) 
        {
            getWorld().removeObject(getOneIntersectingObject(Axe.class));
            resist--;
        }
        if(isTouching(Sword.class))
        {
            getWorld().removeObject(getOneIntersectingObject(Sword.class));
            resist-=2;
        }
    }
}
